<?php

namespace App\Console\Commands;

use App\depository\TsOrderDep;
use App\Models\TsOrderModel;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class DelOrderCmd extends Command{

    //定期清理次数为零的订单
    public $signature = 'order:del';

    public function handle(){

        $this->log('开始删除');
        while(true){
            $resList = TsOrderModel::select(['id'])->where('count',0)->limit(500)->get();
            if($resList->isEmpty()){
                $this->log('删除完毕');
                return true;
            }
            TsOrderModel::whereIn('id',$resList->pluck('id'))->delete();
        }

    }

    public function log($message)
    {
        $this->info($message);
        Log::info($message);
    }
}
